<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>数据权限</title> 
    <link href="${root}/js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="${root}/js/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <script src="${root}/js/lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="${root}/js/lib/ligerUI/js/ligerui.min.js" type="text/javascript"></script>   
    <link href="${root}/js/lib/css/common.css" rel="stylesheet" type="text/css" />  
    <script src="${root}/js/common/common.js" type="text/javascript"></script>   
    <script src="${root}/js/common/LG.js" type="text/javascript"></script>
    <script src="${root}/js/common/ligerui.expand.js" type="text/javascript"></script> 
    <script src="${root}/js/lib/json2.js" type="text/javascript"></script>
    <script src="${root}/js/common/DataPrivilageSysParm.js" type="text/javascript"></script> 
    <style type="text/css">
    .filterpanle{ margin:10px;}
    .l-panel td.l-filter-column,.l-panel td.l-filter-value,.l-panel td.l-filter-op{ padding:2px;}
    
    .l-selected .l-grid-row-cell, .l-selected {background: #F5F5F5;}
    .l-panel td .l-filter-rowlast{ padding-top:1px;}
    
    .l-panel td .l-filter-rowlast {padding:3px;}
        .l-panel td .groupopsel{ margin:1px;}
        .l-panel td .l-filter-cellgroup{ padding:2px;}  
         .l-panel td .l-filter-rowlastcell{ padding:2px;}
    </style>
</head>
<body style="padding:10px;height:100%; text-align:center;">
   <ipnut type="hidden" id="MenuNo" value="sysDataPrivilege" />
  <div id="mainsearch" style=" width:98%"> 
  <div id="maingrid"></div> 
  <script type="text/javascript">
      var ID = '<%=request.getParameter("ID")%>';


      //相对路径
      var rootPath = "${root}/app/";
      //列表结构
      var toolbarOptions = {
          items: [
            { text: '增加', id: 'add', click: toolbarBtnItemClick, img: "${root}/js/lib/icons/silkicons/add.png" },
            { line: true },
            { text: '修改', id: 'modify', click: toolbarBtnItemClick, img: "${root}/js/lib/icons/miniicons/page_edit.gif" },
            { line: true },
            { text: '删除', id: 'delete', click: toolbarBtnItemClick, img: "${root}/js/lib/icons/miniicons/page_delete.gif" },
            { line: true },
            { text: '保存', id: 'save', click: toolbarBtnItemClick,icon:'save' },
            { line: true },
            { text: '取消', id: 'cancel', click: toolbarBtnItemClick,icon:'cancel' }
        ]
      };
      var grid = $("#maingrid").ligerGrid({
          columns: [
          { display: "字段名称", name: "columnName", width: 150, type: "text", align: "left", validate: { required: true }
          , editor: { type: 'text' } },
          { display: "显示名称", name: "showName", width: 150, type: "text", align: "left", validate: { required: true }
          , editor: { type: 'text' } },
          { display: "描述", name: "remark", width: '100%', type: "text", align: "left", editor: { type: 'text' } }
          ], 
          dataAction: 'server', 
          pageSize: 20, 
          toolbar: toolbarOptions,
          url: rootPath + 'sys_col_loadJSON?ID='+ID, 
          sortName: 'columnName', 
          width: '98%', 
          height: '100%',
          heightDiff:-10, 
          checkbox: false,
          usePager:true,
          enabledEdit: true, 
          clickToEdit: false,
          mouseoverRowCssClass : null,
          alternatingRow :false
      }); 
	/*
      var filterCounter = 0;
      var AllfilterData = {};
      function ruleRender(rowdata)
      {
          var rule = rowdata.DataPrivilegeRule;
          var master = rowdata.DataPrivilegeView;
          if (!rule || rule == "{}") return "";
          var ruleData = JSON2.parse(rule);
          AllfilterData['filter' + ++filterCounter] = ruleData;
          return "<div id='filter" + filterCounter + "' master='"+master+"' class='filterpanle'></div>";
      }
      grid.bind('afterShowData', function ()
      {
          $("div.filterpanle", maingrid).each(function ()
          {
              var ruleData = AllfilterData[this.id];
              var master=  $(this).attr("master");
              var filter =  $(this).ligerFilter({fields:getFields(master)});  
              filter.setData(ruleData);
          });
          $(":button,.deleterole",maingrid).remove();
          $("select,input",maingrid).attr("disabled","disabled");
      });

*/
      //工具条事件
      function toolbarBtnItemClick(item)
	      {
	          var editingrow = grid.getEditingRow();
	          switch (item.id) {
	              case "add":
	                  //top.f_addTab(null, '增加角色信息', 'MemberManage/RoleDetail.aspx');
	                  if (editingrow == null)
	                  {
	                      addNewRow();
	                  } else
	                  {
	                      LG.tip('请先提交或取消修改');
	                  }
	                  break;
	              case "cancel":
	            	  if (editingrow != null)
	                  {
	                      grid.cancelEdit(editingrow); 
	                  } else
	                  {
	                      LG.tip('现在不在编辑状态!');
	                  }
	                  break;
	              case "modify":
	                  var selected = grid.getSelected();
	                  if (!selected) { LG.tip('请选择行!'); return }
	                  //top.f_addTab(null, '修改角色信息', 'MemberManage/RoleDetail.aspx?ID=' + selected.RoleID);
	                  if (editingrow == null)
	                  {
	                      beginEdit();
	                  } else
	                  {
	                      LG.tip('请先提交或取消修改');
	                  }
	                  break;
	              case "delete":
	                  jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
	                      if (confirm)
	                          f_delete();
	                  });
	                  break;
	              case "save":
	                  if (editingrow != null)
	                  {
	                      grid.endEdit(editingrow);
	                  } else
	                  {
	                      LG.tip('现在不在编辑状态!');
	                  }
	                  break;
	          }
	      }


      function f_reload() {
          grid.loadData();
      }
      function f_delete() {
          var selected = grid.getSelected();
          if (selected) {
              LG.ajax({
                  type: '/sys_col_remove',
                 // method: '/sys_obj_remove',
                  loading: '正在删除中...',
                  data: { ID: selected.col_id },
                  success: function () {
                      LG.showSuccess('删除成功');
                      f_reload();
                  },
                  error: function (message) {
                      LG.showError(message);
                  }
              });
          }
          else {
              LG.tip('请选择行!');
          }
      }

	grid.bind('beforeSubmitEdit', function (e)
    	      {
    	          //if (!LG.validator.form())
    	          //{
    	          //    LG.showInvalid();
    	         //     return false;
    	         // }
    	          return true;
    	      });
	grid.bind('afterSubmitEdit', function (e)
    	      {
    	          var isAddNew = e.record['__status'] == "add";
    	          var data = $.extend(true, {}, e.newdata);
    	          var str_type = isAddNew ? "/sys_col_add" : "/sys_col_update";
    	          //if (!isAddNew)
    	           data.col_id = e.record.col_id;
    	           data.obj_id=ID;
    	           LG.ajax({
    	              loading: '正在保存数据中...',
    	              type: str_type,
    	              //提交路径
    	              //path:'/addRole',
    	              //method: isAddNew ? "addRole" : "updateRole",
    	              data: data,
    	              success: function ()
    	              { 
    	                  grid.loadData();
    	                  LG.showSuccess("操作成功！");
    	              },
    	              error: function (message)
    	              {
    	                  LG.tip(message);
    	              }
    	          }); 
    	          
    	          return false;
    	      }); 
    	      
      function beginEdit()
      {
          var row = grid.getSelectedRow();
          if (!row) { LG.tip('请选择行'); return; }
          grid.beginEdit(row); 
      }
      function addNewRow()
      {
          grid.addEditRow();
      }
  </script>
</body>
</html>
